﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;

namespace c2iGMailNotifier.Service
{
    public class RegistryService
    {
        public const string REGKEYNAME = "c2i-GMailNotifier";

        public static void SetWindowsStartValue(bool show)
        {
            System.Reflection.Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();
            RegistryKey regKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

            if (ass == null || regKey == null)
                return;

            if (!show)
                regKey.DeleteValue(REGKEYNAME);
            else
                regKey.SetValue(REGKEYNAME, ass.Location);

            System.Diagnostics.Debug.WriteLine("SetWindowsStartValue");
        }

        public static bool GetWindowsStartValue()
        {
            System.Diagnostics.Debug.WriteLine("GetWindowsStartValue");

            RegistryKey regKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
                                                                 true);
            if (regKey == null)
                return false;
            object regKeyValue = regKey.GetValue(REGKEYNAME);

            if (regKeyValue == null ||regKeyValue.ToString() != System.Reflection.Assembly.GetExecutingAssembly().Location)
                return false;

            return true;
        }

    }
}